package com.yzc.mihuyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yzc.mihuyou.entity.Give;
import com.yzc.mihuyou.mapper.GiveMapper;
import com.yzc.mihuyou.service.GiveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 收藏表 服务实现类
 * </p>
 *
 * @author 易紫诚
 * @since 2022-04-28
 */
@Service
public class GiveServiceImpl extends ServiceImpl<GiveMapper, Give> implements GiveService {

    @Autowired
    GiveMapper giveMapper;

    @Override
    public int owGive(Give give,int i) {
        QueryWrapper<Give> queryWrapper=new QueryWrapper<>();
        queryWrapper
                 .eq("give_userid",give.getGiveUserid())
                 .eq("invitation_id",give.getInvitationId());
        Give give1=giveMapper.selectOne(queryWrapper);
        System.out.println(give1);
        if(give1!=null){
            int p=0;
            if(i==1){
                p=give1.getInvtationPrin()==0?1:0;
                give1.setInvtationPrin(p);
            }else {
                p=give1.getInvtationOre()==0?1:0;
                give1.setInvtationOre(p);
            }
            giveMapper.update(give1,queryWrapper);
        }else{
            if(i==1){
                give.setInvtationPrin(1);
                give.setInvtationOre(0);
            }else {
                give.setInvtationPrin(0);
                give.setInvtationOre(1);
            }
            giveMapper.insert(give);
        }
        return 1;
    }

    @Override
    public List<Give> themeGood(long id) {
        List<Give> list = giveMapper.themeGood(id);

        return list;
    }
}
